/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EmpleadoView.java
 *
 * Created on 07/12/2009, 11:05:30 AM
 */

package vista;

import controlador.IEmpleadoController;
import modelo.IEmpleado;
import modelo.IEmpleadoModel;
/**
 *
 * @author LEONIC
 */
public class EmpleadoView extends javax.swing.JFrame implements IEmpleadoView {

    private IEmpleadoModel model;
    private IEmpleadoController controller;

    private EmpleadoTableModel tableModel;
    private JPanelEmpleado panelEmpleado;

    /** Creates new form EmpleadoView */
    public EmpleadoView() {
        tableModel=new EmpleadoTableModel();
        initComponents();

        this.panelEmpleado=new JPanelEmpleado(this);
        this.panelabajo.add(this.panelEmpleado);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTableEmpleado = new javax.swing.JTable();
        panelabajo = new javax.swing.JPanel();

        setTitle("Gestión de Empleados - Departamento RR.HH");

        jTableEmpleado.setModel(tableModel);
        jTableEmpleado.setUpdateSelectionOnSort(false);
        jTableEmpleado.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableEmpleadoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableEmpleado);

        panelabajo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        panelabajo.setLayout(new javax.swing.BoxLayout(panelabajo, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelabajo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 689, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 689, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(panelabajo, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTableEmpleadoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableEmpleadoMouseClicked
        EmpleadoTableModel ctm=(EmpleadoTableModel)this.jTableEmpleado.getModel();
        IEmpleado empleado=ctm.getRow(this.jTableEmpleado.getSelectedRow());
        this.panelEmpleado.setEmpleado(empleado);
}//GEN-LAST:event_jTableEmpleadoMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EmpleadoView().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableEmpleado;
    private javax.swing.JPanel panelabajo;
    // End of variables declaration//GEN-END:variables

    public IEmpleadoController getController() {
        return controller;
    }

    public void setController(IEmpleadoController controller) {
        this.controller=controller;
    }

    public IEmpleadoModel getModel() {
        return model;
    }

    public void setModel(IEmpleadoModel model) {
        this.model=model;
    }

    public void dataModelChanged() {
        refresh();
    }

    public void display() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                setVisible(true);
                refresh();
            }
        });
    }

    protected void refresh() {
        this.tableModel.setEmpleados(getModel().obtenerEmpleado());
    }

    protected void fireActualizaEmpleadoGesture(String dni, String nombre, double salario, String tarea, String rol, boolean empleado, int codTienda, String usuario, String password, double pluses) {
        getController().actualizaEmpleadoGesture(dni, nombre, salario, tarea, rol, empleado, codTienda, usuario, password, pluses);
    }

    protected void fireBorraEmpleadoGesture(String dni){
        getController().borraEmpleadoGesture(dni);
    }
}
